#include <iostream>

#include "include/PionManager.h"
#include "include/ModelX3D.h"
#include "tinyxml/tinyxml.h"

using namespace std;


PionManager::PionManager()
{
   loadModel3DPionLevel1();
   loadModel3DPionLevel2();
   loadModel3DPionLevel3();
}

void PionManager::loadModel3DPion(const char * _modelPath, Model3D * _model3DPion)
{
   TiXmlDocument doc(_modelPath);
   
   if( !doc.LoadFile() )
   {
      cerr << "erreur lors du chargement de " << _modelPath << endl;
      cerr << "error #" << doc.ErrorId() << " : " << doc.ErrorDesc() << endl;
      exit(0);
   }
   TiXmlNode * node = doc.RootElement();
   node = node->FirstChild()->NextSibling()->FirstChild("Transform");
   node = node->FirstChild()->FirstChildElement("IndexedFaceSet");

   ModelX3D::computeShapeIndex(node->ToElement()->Attribute("coordIndex"), _model3DPion);
   ModelX3D::computeShape(node->FirstChildElement("Coordinate")->Attribute("point"), _model3DPion);
}

Model3D * PionManager::getModel3DPion(Level _level)
{
   switch (_level)
   {
      case LEVEL1:
         return &pionLevel1;
      case LEVEL2:
         return &pionLevel2;
      case LEVEL3: 
         return &pionLevel3;
      default:
         return &pionLevel1;
   }
}

void PionManager::loadModel3DPionLevel1(const char * _modelPath)
{
   loadModel3DPion(_modelPath, &pionLevel1);
}

void PionManager::loadModel3DPionLevel2(const char * _modelPath)
{
   loadModel3DPion(_modelPath, &pionLevel2);
}

void PionManager::loadModel3DPionLevel3(const char * _modelPath)
{
   loadModel3DPion(_modelPath, &pionLevel3);
}



